package com.thz.friend.service.video.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.thz.common.core.constants.Constants;
import com.thz.common.core.utlis.ThreadLocalUtil;
import com.thz.friend.mapper.report.ReportMapper;
import com.thz.friend.mapper.video.VideoMapper;
import com.thz.friend.pojo.report.Report;
import com.thz.friend.pojo.video.Video;
import com.thz.friend.service.video.IVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

/**
 * @Description
 * @Author thz
 * @Date 2025/5/11
 */
@Service
public class videoServiceImpl implements IVideoService {

    @Autowired
    private VideoMapper videoMapper;

    @Autowired
    private ReportMapper reportMapper;

    @Value("${video.upload.path:E:\\javaProject\\java\\java\\20250226\\algorithm-oj\\upload\\directory}")
    private String uploadPath;

    @Override
    public List<Video> list(Long courseId) {
        List<Video> videoList = videoMapper.selectList(new LambdaQueryWrapper<Video>()
                .eq(Video::getCourseId, courseId));
        return videoList;
    }

    @Override
    public Video getVideoById(Long videoId,Long courseId) {

        Long userId = ThreadLocalUtil.get(Constants.USER_ID, Long.class);

        Report reports = reportMapper.selectOne(new LambdaQueryWrapper<Report>()
                .eq(Report::getVideoId, videoId).eq(Report::getCreateUser,userId));

        if (reports == null) {
            Report report = new Report();
            report.setVideoId(videoId);
            report.setCourseId(courseId);
            reportMapper.insert(report);
        }

        return videoMapper.selectById(videoId);
    }

}
